﻿using Chaotic.Core.Extension;
using Chaotic.DataBase.DBAccessLibrary.DBAccessLibrary;
using Chaotic.Module.DBTool.Models;
using Chaotic.Module.DBTool.ViewModels;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Chaotic.Module.DBTool.Views
{
    /// <summary>
    /// OutPutGridView.xaml 的交互逻辑
    /// </summary>
    public partial class OutPutGridContent : UserControl
    {
        string _Sql;
        public OutPutGridContent()
        {
            InitializeComponent();
            this.Loaded += OutPutGridView_Loaded; 
        }
        public OutPutGridContent(string sql)
        {
            _Sql = sql;
            InitializeComponent();
            this.Loaded += OutPutGridView_Loaded;  
        }

  

        private async void OutPutGridView_Loaded(object sender, RoutedEventArgs e)
        {
            //找到父节点的RadDocking控件

            if (this.Parent is Telerik.Windows.Controls.RadPane pane)
            {
                if (this.DataContext is OutPutGridContentViewModel viewModel)
                {
                    viewModel.FocusTabActive = () =>
                    {
                        //激活当前选项卡
                        pane.IsSelected = true;
                        pane.IsActive = true;
                    };

                    if (!string.IsNullOrEmpty(_Sql))
                    {
                        viewModel.LoadDataAsync(_Sql);
                    }
                }
            }
        }

        private void gridview_AutoGeneratingColumn(object sender, Telerik.Windows.Controls.GridViewAutoGeneratingColumnEventArgs e)
        {
             if(e.Column.Header.ToString() == "ROWNUMBER")
            {
                e.Cancel = true;
            }
        }

        private void gridview_CopyingCellClipboardContent(object sender, Telerik.Windows.Controls.GridViewCellClipboardEventArgs e)
        { 
        }
    }
}
